package com.yootk.server;
import java.io.*;
import java.net.*;

public class HelloServer {
    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(9999);
        System.out.println("【HelloServer】服务端启动监听......");

        // 等待客户端连接（阻塞式I/O）
        Socket client = serverSocket.accept();
        System.out.println("客户端连接成功：" + client.getInetAddress());

        // 获取输出流向客户端发送数据
        PrintStream out = new PrintStream(client.getOutputStream());
        out.println("www.rootk.com");

        // 关闭输出流并释放资源
        client.shutdownOutput();
        client.close();
        serverSocket.close();
        System.out.println("服务端关闭");
    }
}